﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections;

namespace proLearningEnglish
{
    public partial class frmSelectTest : Form
    {
        public frmSelectTest()
        {
            InitializeComponent();
        }

        private void frmSelectTest_Load(object sender, EventArgs e)
        {
            loadTest();
        }

        private void loadTest()
        {
            List<Test> lst = frmMain.objDataManager.getTest();
            foreach (Test t in lst)
            {
                this.cmbTest.Items.Add(t.getName());
            }
            this.cmbTest.Tag = lst;
        }

        private void txtPupilName_Leave(object sender, EventArgs e)
        {
            string str = this.txtPupilName.Text.Trim();
            str = Regex.Replace(str, " +", " ");
            this.txtPupilName.Text = str;   
        }

        private void btnBegin_Click(object sender, EventArgs e)
        {
            frmTesting frm = new frmTesting(((List<Test>)this.cmbTest.Tag)[this.cmbTest.SelectedIndex], this.txtPupilName.Text);
            frm.Show();
            this.Dispose();
        }

        private void cmbTest_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.txtPupilName.Text != null && this.txtPupilName.Text != "")
            {
                this.btnBegin.Enabled = true;
            }
        }

        private void txtPupilName_TextChanged(object sender, EventArgs e)
        {
            this.btnBegin.Enabled = (this.cmbTest.SelectedIndex != -1 && !this.txtPupilName.Text.Equals(""));
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
